package entity;

public class PersistenceLayer {

	private UserDAO userDAO; 
	private ManagerDAO managerDAO;
	private SexDAO sexDAO;

    public UserDAO getUserDAO() { 
        return userDAO; 
    } 

    public void setUserDAO(UserDAO userDAO) { 
        this.userDAO = userDAO; 
    } 
    
    public void addUser(User user) { 
        userDAO.save(user); 
    } 
    
    public User findUserById(Integer id) { 
        return userDAO.findById(id); 
    } 
    
    public void updateUser(User user) { 
        userDAO.merge(user); 
    } 
    
    public void deleteUser(User user) { 
        userDAO.delete(user); 
    }

    
	public ManagerDAO getManagerDAO() {
		return managerDAO;
	}

	public void setManagerDAO(ManagerDAO managerDAO) {
		this.managerDAO = managerDAO;
	}

	public SexDAO getSexDAO() {
		return sexDAO;
	}

	public void setSexDAO(SexDAO sexDAO) {
		this.sexDAO = sexDAO;
	}

	public User checkUser(String userName, String userPassword) {
		// TODO Auto-generated method stub
		return userDAO.checkUser(userName, userPassword);
	}

	public boolean checkManager(String managerName, String managerPassword) {
		// TODO Auto-generated method stub
		return getManagerDAO().checkManager(managerName, managerPassword);
	}

	public Sex findSex(int id) {
		// TODO Auto-generated method stub
		return getSexDAO().findById(id);
	}

	public boolean isUserNameExist(String userName) {
		return getUserDAO().findByUserName(userName).size() > 0;
	}

	public int updateUserInfor(User user) {
		// TODO Auto-generated method stub
		return getUserDAO().updateUserInfor(user);
	}

}
